﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using System.Xml.Linq;

namespace EasyXaf.LowCode.WorkflowEditors.Models.Activities;

[DomainComponent]
[ImageName("WF_While")]
[XafDisplayName("条件循环(While)")]
[ActivityOrder(40)]
[ActivityGroup(ActivityGroupConsts.CommonGroupName)]
public class WhileActivity : ContainerActivity
{
    public override string ImageName => "WF_While";

    public override bool HasDetailView => true;

    [XafDisplayName("条件")]
    public string Condition
    {
        get => GetPropertyValue<string>();
        set => SetPropertyValue(value);
    }

    public WhileActivity(IWorkflow workflow, ISequence sequence)
        : base(workflow, sequence)
    {
        Caption = "条件循环";
    }

    public override void WriteStateToXml(XElement element)
    {
        base.WriteStateToXml(element);

        SetXmlValue(element, nameof(Condition), Condition);
    }

    public override void ReadStateFromXml(XElement element)
    {
        base.ReadStateFromXml(element);

        Condition = GetXmlValue<string>(element, nameof(Condition));
    }
}
